package com.yunxi.controller.vip;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.order.service.OrderVehicleDubboService;
import com.yunxi.sat.pojo.HandleVehicleVO;
import com.yunxi.sat.service.HandleVehicleDubboService;
import com.yunxi.sto.service.VehicleStockDubboService;
import com.yunxi.vip.pojo.StoVehicleExpVO;
import com.yunxi.vip.pojo.VipApplyVO;
import com.yunxi.vip.pojo.VipManageVO;
import com.yunxi.vip.pojo.VipVO;
import com.yunxi.vip.service.StoVehicleExpDubboService;
import com.yunxi.vip.service.VipApplyDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2019-09-06
 */
@RestController
@RequestMapping("/admin/vipManage")
@Api(tags = "pms:vipManage", description = "接口")
public class VipManageController {
 private static final Logger logger = LoggerFactory.getLogger(VipManageController.class);

    @Autowired
    VehicleStockDubboService vehicleStockDubboService;

    @Autowired
    OrderVehicleDubboService orderVehicleDubboService;

    @Autowired
    StoVehicleExpDubboService stoVehicleExpDubboService;

    @Autowired
    HandleVehicleDubboService handleVehicleDubboService;

    /** 查詢大客戶订货单数据 */

    /** 绑定订货单 */
    @PostMapping("/band")
    @ApiOperation(value = "绑定订货单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "orderCustomerNo", value = "lingshoudanhao", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="query", name = "orderCarId", value = "dinghuodan", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult band(String orderCustomerNo,String orderCarId, @CurrentUser LoginInfo loginInfo) throws Exception {
        orderVehicleDubboService.band(orderCustomerNo,orderCarId);
        return ResponseUtil.ok();
    }

    /** 绑定exp */
    @PostMapping("/bandExp")
    @ApiOperation(value = "绑定渠道商体验车库存")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "orderCustomerNo", value = "lingshoudanhao", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="query", name = "orderCarId", value = "dinghuodan", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult bandExp(String orderCustomerNo,String vin, @CurrentUser LoginInfo loginInfo) throws Exception {
        orderVehicleDubboService.bandExp(orderCustomerNo,vin);
        return ResponseUtil.ok();
    }

    /** 解绑订货单 */
    @PostMapping("/unband")
    @ApiOperation(value = "解绑订货单")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "orderCarId", value = "dinghuodan", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult unband(String orderCarId, @CurrentUser LoginInfo loginInfo) throws Exception {
        orderVehicleDubboService.unband(orderCarId);
        return ResponseUtil.ok();
    }

    /** 车辆初始化 */
    @PostMapping("/hireInit")
    @ApiOperation(value = "车辆初始化")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "vin", value = "vin碼", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult hireInit(String vin, @CurrentUser LoginInfo loginInfo) throws Exception {
        orderVehicleDubboService.hireInit(vin);
        return ResponseUtil.ok();
    }

    @GetMapping("/pageHandleVehicle")
    @ApiOperation(value = "查询大客户交车信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "orderCustomerNo", value = "lingshoudanhao", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="query", name = "orderCarId", value = "dinghuodan", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult pageHandleVehicle(VipManageVO vipApplyVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
       if(loginInfo.getPartnerCode()!=null){
          vipApplyVO.setPartnerCode(loginInfo.getPartnerCode());
       }else{
          vipApplyVO.setPartnerCodeNot("true");
       }
        return ResponseUtil.ok(stoVehicleExpDubboService.pageHandleVehicle(vipApplyVO,pageNum,pageSize));
    }

    @GetMapping("/pageActualSales")
    @ApiOperation(value = "查询大客户实销信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "orderCustomerNo", value = "lingshoudanhao", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="query", name = "orderCarId", value = "dinghuodan", required = true, dataType = "string")
    })
    @Deprecated
    public ApiResult pageActualSales(VipManageVO vipApplyVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
       if(loginInfo.getPartnerCode()!=null){
          vipApplyVO.setPartnerCode(loginInfo.getPartnerCode());
          vipApplyVO.setSubmitType(0);
       }else
       {
          vipApplyVO.setSubmitType(1);
       }
        return ResponseUtil.ok(stoVehicleExpDubboService.pageActualSales(vipApplyVO,pageNum,pageSize));
    }
}
